/*
 * Copyright 2024-2025 the original author or authors.
 */

package io.modelcontextprotocol.sdk;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.ArrayList;
import java.util.List;

/**
 * Weather forecast data model.
 *
 * @author MCP Java SDK Example
 */
public class WeatherForecast {

	private final String city;

	private final String country;

	private final List<ForecastEntry> forecasts;

	public WeatherForecast(String city, String country, MockWeatherService.ForecastItem[] forecastItems) {
		this.city = city;
		this.country = country;
		this.forecasts = new ArrayList<>();

		for (MockWeatherService.ForecastItem item : forecastItems) {
			forecasts.add(new ForecastEntry(item.dateTime, item.main.temp, item.main.feelsLike, item.main.humidity,
					item.weather[0].main, item.weather[0].description, item.wind.speed));
		}
	}

	public String getCity() {
		return city;
	}

	public String getCountry() {
		return country;
	}

	public List<ForecastEntry> getForecasts() {
		return forecasts;
	}

	public static class ForecastEntry {

		private final String dateTime;

		private final double temperature;

		private final double feelsLike;

		private final int humidity;

		private final String condition;

		private final String description;

		private final double windSpeed;

		public ForecastEntry(String dateTime, double temperature, double feelsLike, int humidity, String condition,
				String description, double windSpeed) {
			this.dateTime = dateTime;
			this.temperature = temperature;
			this.feelsLike = feelsLike;
			this.humidity = humidity;
			this.condition = condition;
			this.description = description;
			this.windSpeed = windSpeed;
		}

		@JsonProperty("date_time")
		public String getDateTime() {
			return dateTime;
		}

		public double getTemperature() {
			return temperature;
		}

		@JsonProperty("feels_like")
		public double getFeelsLike() {
			return feelsLike;
		}

		public int getHumidity() {
			return humidity;
		}

		public String getCondition() {
			return condition;
		}

		public String getDescription() {
			return description;
		}

		@JsonProperty("wind_speed")
		public double getWindSpeed() {
			return windSpeed;
		}

		@Override
		public String toString() {
			return String.format("%s: %.1f°C (%s) - %s", dateTime, temperature, condition, description);
		}

	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append(String.format("Weather forecast for %s, %s:\n", city, country));
		for (ForecastEntry forecast : forecasts) {
			sb.append(forecast.toString()).append("\n");
		}
		return sb.toString();
	}

}
